#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import socketserver


class Mysock(socketserver.BaseRequestHandler):
    def handle(self):
        print("服务启动成功: ")
        try:
            while True:
                print("来自:{0} 连接成功".format(self.client_address))
                data = self.request.recv(1024).decode()
                print('来自: {0} 发送的数据: {1}'.format(self.client_address, data))
                self.request.sendall(data.encode())
        except Exception:
            print("{0} 断开连接".format(self.client_address))


if __name__ == '__main__':
    sk = socketserver.ThreadingTCPServer(('127.0.0.1', 6667), Mysock)
    sk.serve_forever()
